#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef struct person
{
    int num;
    struct person* next;
}Per;
void cirlist(Per** pphead, int n)
{
    assert(pphead);
    Per* pcur = *pphead;
    int i = 0;
    while (n--)
    {
        Per* newnode = (Per*)malloc(sizeof(Per));
        if (newnode == NULL)
        {
            perror("malloc");
            exit(1);
        }
        newnode->num = ++i;
        newnode->next = NULL;
        if (*pphead == NULL)
        {
            *pphead = pcur = newnode;
        }
        else {
            pcur->next = newnode;
            pcur = newnode;
        }
    }
    pcur->next = *pphead;
}
int count(Per* phead, int m, int n)
{
    Per* prev = phead;
    Per* pcur = phead;
    Per* next = phead->next;
    int i = 0;
    while (n != 1)
    {
        i++;
        if (i == m)
        {
            prev->next = next;
            free(pcur);
            pcur = NULL;
            n--;
            i = 0;
        }
        else {
            prev = pcur;

        }
        pcur = next;
        next = next->next;
    }
    return prev->num;
}
int ysf(int n, int m) {
    // write code here
    Per* phead = NULL;
    cirlist(&phead, n);
    int number = count(phead, m, n);
    return number;
}

int main()
{
    printf("%d", ysf(5, 2));
    return 0;
}